package com.zhengshang.web.controller.app;

import com.zhengshang.api.domain.AppGoodsChannel;
import com.zhengshang.api.service.IAppGoodsChannelService;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.core.page.TableDataInfo;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 电商频道Controller
 *
 * @author zhengshang
 * @date 2022-04-16
 */
@RestController
@RequestMapping("/app/goodsChannel")
public class AppGoodsChannelController extends BaseController {
    @Autowired
    private IAppGoodsChannelService appGoodsChannelService;

    /**
     * 查询电商频道列表
     */
    @PreAuthorize("@ss.hasPermi('app:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppGoodsChannel appGoodsChannel) {
        startPage();
        List<AppGoodsChannel> list = appGoodsChannelService.selectAppGoodsChannelList(appGoodsChannel);
        return getDataTable(list);
    }

    /**
     * 查询电商频道列表
     */
    @PreAuthorize("@ss.hasPermi('app:channel:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(@RequestParam(required = false)Map params) {
        startPage();
        List<Map> list = appGoodsChannelService.selectAppGoodsChannelList1(params);
        return getDataTable(list);
    }
    /**
     * 导出电商频道列表
     */
    @PreAuthorize("@ss.hasPermi('app:channel:export')")
    @Log(title = "电商频道", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppGoodsChannel appGoodsChannel) {
        List<AppGoodsChannel> list = appGoodsChannelService.selectAppGoodsChannelList(appGoodsChannel);
        ExcelUtil<AppGoodsChannel> util = new ExcelUtil<AppGoodsChannel>(AppGoodsChannel.class);
        return util.exportExcel(list, "channel");
    }

    /**
     * 获取电商频道详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:channel:query')")
    @GetMapping(value = "/{goodsChannelId}")
    public AjaxResult getInfo(@PathVariable("goodsChannelId") Long goodsChannelId) {
        return AjaxResult.success(appGoodsChannelService.selectAppGoodsChannelById(goodsChannelId));
    }

    /**
     * 新增电商频道
     */
    @PreAuthorize("@ss.hasPermi('app:channel:add')")
    @Log(title = "电商频道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGoodsChannel appGoodsChannel) {
        return toAjax(appGoodsChannelService.insertAppGoodsChannel(appGoodsChannel));
    }

    /**
     * 修改电商频道
     */
    @PreAuthorize("@ss.hasPermi('app:channel:edit')")
    @Log(title = "电商频道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGoodsChannel appGoodsChannel) {
        return toAjax(appGoodsChannelService.updateAppGoodsChannel(appGoodsChannel));
    }

    /**
     * 删除电商频道
     */
    @PreAuthorize("@ss.hasPermi('app:channel:remove')")
    @Log(title = "电商频道", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsChannelIds}")
    public AjaxResult remove(@PathVariable Long[] goodsChannelIds) {
        return toAjax(appGoodsChannelService.deleteAppGoodsChannelByIds(goodsChannelIds));
    }
}
